package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/supplier")
@RestController
public class SupplierController {
    @Autowired
    SupplierService supplierService;

    @PostMapping("/list")
    public Map<String,Object> list(Integer page, Integer rows, String supplierName){
        return supplierService.findPage(page,rows,supplierName);
    }
    @PostMapping("/save")
    public ServiceVO saveOrUpdate(@RequestParam(value = "supplierId",required = false) Integer supplierId,
                                  Supplier supplier){
        supplierService.saveOrUpdate(supplierId,supplier);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }
    @PostMapping("/delete")
    public ServiceVO delete(String ids){
        supplierService.delete(ids);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

}
